<!--  -->
<template>
    <div >
        <a-page-header
            style="border: 1px solid rgb(235, 237, 240);background:#fff"
            :title="`${vehicleName}-租车门店配置`"
            @back="() => $router.go(-1)"
        >
            <div class='table-page-search-wrapper'>
                <a-form layout='inline'>
                    <a-row :gutter='48'>
                        <a-col :md='8' :sm='24'>
                            <a-form-item label="租车门店">
                                <a-select v-model="storeId" placeholder="请选择" allowClear @change="getData">
                                    <a-select-option v-for="(item,i) in storeList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        <a-col :md='8' :sm='24'>
                            <a-form-item label="状态">
                                <a-select v-model="status" placeholder="请选择" allowClear @change="getData">
                                    <a-select-option v-for="(item,i) in statusList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        <a-col :md='8' :sm='24'>
                            <a-form-item >
                                <a-button type="primary" style="margin-right: 20px" @click="getData()">查询</a-button>
                                <a-button type="" icon="plus" @click="add()">添加</a-button>
                            </a-form-item>
                        </a-col>
                    </a-row>
                </a-form>
            </div>  
            <a-table rowKey="id" :loading="isload" :columns="columns" :data-source="dataList" @change="handleTableChange" :pagination="{ total: total ,showSizeChanger: true,pageSize: size,}" size="small">
                <div slot="realShotImage" slot-scope="text,record">
                    <img style="width: 120px;height: 60px" v-if="record.realShotImage && record.realShotImage.substring(0,4) == 'http'" :src="record.realShotImage && record.realShotImage.split(',')[0]" alt="" @click="showImg(record.realShotImage)">
                    <div v-else>-</div>
                </div>
                <div slot="storeId" slot-scope="storeId">
                    <div v-for="(item,i) in storeList" :key="item.id">
                        <a-tag v-if="item.id == storeId" :color="colors[i%13]">{{item.name}}</a-tag>
                    </div>
                </div>
                <div slot="rent" slot-scope="rent">
                    <div v-if="rent">{{rent}}元/天</div>
                    <div v-else>-</div>
                </div>
                <div slot="commission" slot-scope="commission">
                    <div v-if="commission">{{commission }}元</div>
                    <div v-else>-</div>
                </div>
                <div slot="deliveryFee" slot-scope="deliveryFee">
                    <div v-if="deliveryFee">{{deliveryFee * 100}}%</div>
                    <div v-else>-</div>
                </div>
                <div slot="pickUpFee" slot-scope="pickUpFee">
                    <div v-if="pickUpFee">{{pickUpFee * 100}}%</div>
                    <div v-else>-</div>
                </div>
                <div slot="freeCancleTime" slot-scope="freeCancleTime">
                    <div v-if="freeCancleTime">{{freeCancleTime}}分钟</div>
                    <div v-else>-</div>
                </div>
                <div slot="beforePickUpDedit" slot-scope="beforePickUpDedit">
                    <div v-if="beforePickUpDedit">{{beforePickUpDedit * 100}}%</div>
                    <div v-else>-</div>
                </div>
                <div slot="afterPickUpDedit" slot-scope="afterPickUpDedit">
                    <div v-if="afterPickUpDedit">{{afterPickUpDedit * 100}}%</div>
                    <div v-else>-</div>
                </div>
                <div slot="rentalCarCashPledge" slot-scope="rentalCarCashPledge">
                    <div v-if="rentalCarCashPledge">{{rentalCarCashPledge}}元</div>
                    <div v-else>-</div>
                </div>
                <div slot="breakRulesCashPledge" slot-scope="breakRulesCashPledge">
                    <div v-if="breakRulesCashPledge">{{breakRulesCashPledge}}元</div>
                    <div v-else>-</div>
                </div>
                <div slot="limitMileage" slot-scope="limitMileage">
                    <div v-if="limitMileage">{{limitMileage}}km/天</div>
                    <div v-else>-</div>
                </div>
                <div slot="overLimitFee" slot-scope="overLimitFee">
                    <div v-if="overLimitFee">{{overLimitFee}}元/km</div>
                    <div v-else>-</div>
                </div>
                <div slot="prohibitArea" slot-scope="prohibitArea">
                    <div v-if="prohibitArea">{{prohibitArea}}</div>
                    <div v-else>-</div>
                </div>
                <div slot="status" slot-scope="status">
                    <a-switch checked-children="开" un-checked-children="关" disabled :checked="status == '1' ? true : false" />
                </div>
                <div slot="safeguardConfig" slot-scope="text,record">
                    <a-button type="link" @click="setSafeConfig(record)">设置</a-button>
                </div>
                <div slot="operation" slot-scope="text,record">
                    <a-button type="link" @click="update(record)">修改</a-button>
                    <a-popconfirm
                        title="是否确认删除当前配置?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="del(record)"
                    >
                        <a-button class="errorColor" type="link">删除</a-button>
                    </a-popconfirm>
                </div>
            </a-table>
        </a-page-header>

        <a-modal
            title="添加、修改租车门店配置信息"
            :visible="visible"
            @ok="handleOk"
            :confirm-loading="confirmLoading"
            @cancel="visible = false"
            >
            <div>
                <a-form :label-col="{ span: 8 }" :wrapper-col="{ span: 14 }">
                    <a-form-item label="租车门店">
                        <a-select v-model="item.storeId" placeholder="请选择" allowClear>
                            <a-select-option v-for="(item,i) in storeList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                        </a-select>
                    </a-form-item>
                    <a-form-item label="租金(单位:天)">
                        <a-input v-model="item.rent" placeholder="请输入车辆每日租金" suffix="元/日" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="手续费">
                        <a-input v-model="item.commission" placeholder="请输入租车手续费" suffix="元" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="送车上门服务费">
                        <a-input v-model="item.deliveryFee" placeholder="请输入送车上门服务费" suffix="%" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="上门取车服务费">
                        <a-input v-model="item.pickUpFee" placeholder="请输入上门取车服务费" suffix="%" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="免费取消时间">
                        <a-input v-model="item.freeCancleTime" placeholder="请输入免费取消时间" suffix="分钟" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="取车时间前违约金">
                        <a-input v-model="item.beforePickUpDedit" placeholder="请输入取车时间前违约金" suffix="%" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="取车时间后违约金">
                        <a-input v-model="item.afterPickUpDedit" placeholder="请输入取车时间后违约金" suffix="%" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="租车押金">
                        <a-input v-model="item.rentalCarCashPledge" placeholder="请输入租车押金" suffix="元" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="违章押金">
                        <a-input v-model="item.breakRulesCashPledge" placeholder="请输入违章押金" suffix="元" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="限制里程(单位：km/天)">
                        <a-input v-model="item.limitMileage" placeholder="请输入每日限制里程" suffix="km/天" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="超限费用(单位：元/km)">
                        <a-input v-model="item.overLimitFee" placeholder="请输入每公里超限费用" suffix="元/km" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="禁行区域">
                        <a-input v-model="item.prohibitArea" placeholder="请输入禁行区域" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="库存数量">
                        <a-input v-model="item.stock" placeholder="请输入车辆库存数量" allow-clear></a-input>
                    </a-form-item>
                    <a-form-item label="状态">
                        <a-radio-group v-model="item.status" >
                            <a-radio  v-for="(item,i) in statusList" :key="i" :value="item.id">{{item.name}}</a-radio>
                        </a-radio-group>
                    </a-form-item>
                </a-form>
            </div>
        </a-modal>

        <!-- 上传图片预览 -->
        <a-modal :visible="previewVisible" :footer="null" @cancel="previewVisible = false">
            <img alt="example" style="width: 100%" :src="previewImage" />
        </a-modal>
        <!-- 表格图片预览 -->
        <a-modal :visible="previewImgVisible" :footer="null" @cancel="previewImgVisible = false">
            <a-carousel autoplay dots-class="slick-dots slick-thumb" arrows style="margin-bottom:60px">
                <div v-for="(img,i) in showImgs" :key="i">
                    <img :src="img" alt=""/>
                </div>
                <a slot="customPaging" slot-scope="props">
                    <img :src="getImgUrl(props.i)" />
                </a>
            </a-carousel>
        </a-modal>

        <a-drawer :title="`${vehicleName}-${safeStoreName}-商家保障配置`" width="80%" :closable="false" :visible="safeConfig" @close="safeConfig = false">
            <div class='table-page-search-wrapper'>
                <a-form layout='inline'>
                    <a-row :gutter='48'>
                        <a-col :md='8' :sm='24'>
                            <a-form-item label="租车保障">
                                <a-select v-model="safeguardId" placeholder="请选择" allowClear @change="getSafeData">
                                    <a-select-option v-for="(item,i) in safeguardList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        <a-col :md='8' :sm='24'>
                            <a-form-item label="是否默认">
                                <a-select v-model="isDefault" placeholder="请选择" allowClear @change="getSafeData">
                                    <a-select-option v-for="(item,i) in isDefaultList" :key="i" :value="item.id">{{item.name}}</a-select-option>
                                </a-select>
                            </a-form-item>
                        </a-col>
                        <a-col :md='8' :sm='24'>
                            <a-form-item >
                                <a-button type="primary" style="margin-right: 20px" @click="getSafeData()">查询</a-button>
                                <a-button type="" icon="plus" @click="safeAdd()">添加</a-button>
                            </a-form-item>
                        </a-col>
                    </a-row>
                </a-form>
            </div>  
            <a-table rowKey="id" :loading="isload" :columns="safeColumns" :data-source="safeList" @change="safeHandleTableChange" :pagination="{ total: safeTotal ,showSizeChanger: true,pageSize: safeSize,}" size="small">
                <div slot="storeId" slot-scope="storeId">
                    <div v-for="(item,i) in storeList" :key="item.id">
                        <a-tag v-if="item.id == storeId" :color="colors[i%13]">{{item.name}}</a-tag>
                    </div>
                </div>
                <div slot="safeguardId" slot-scope="safeguardId">
                    <div v-for="(item,i) in safeguardList" :key="item.id">
                        <a-tag v-if="item.id == safeguardId" :color="colors[i%13]">{{item.name}}</a-tag>
                    </div>
                </div>
                <div slot="isDefault" slot-scope="isDefault">
                    <div v-for="(item,i) in isDefaultList" :key="item.id">
                        <a-tag v-if="item.id == isDefault" :color="colors[i%13]">{{item.name}}</a-tag>
                    </div>
                </div>
                <div slot="safeguardContent" slot-scope="safeguardContent">
                    <ellipsis :length="60" tooltip>{{ safeguardContent == '' || !safeguardContent ? '-' : safeguardContent }}</ellipsis>
                </div>
                <div slot="status" slot-scope="status">
                    <a-switch checked-children="开" un-checked-children="关" disabled :checked="status == '1' ? true : false" />
                </div>
                <div slot="operation" slot-scope="text,record">
                    <a-button type="link" @click="safeUpdate(record)">修改</a-button>
                    <a-popconfirm
                        title="是否确认删除当前配置?"
                        ok-text="Yes"
                        cancel-text="No"
                        @confirm="safeDel(record)"
                    >
                        <a-button class="errorColor" type="link">删除</a-button>
                    </a-popconfirm>
                </div>
            </a-table>
            <a-drawer :title="`添加、修改${vehicleName}-${safeStoreName}商家保障配置`" width="65%" :closable="false" :visible="childrenDrawer" @close="childrenDrawer = false">
                <div>
                    <a-form :label-col="{ span: 8 }" :wrapper-col="{ span: 14 }">
                        <a-form-item label="租车保障">
                            <a-select v-model="safeItem.safeguardId" placeholder="请选择" allowClear>
                                <a-select-option v-for="(item,i) in safeguardList" :key="i" :value="item.id.toString()">{{item.name}}</a-select-option>
                            </a-select>
                        </a-form-item>
                        <a-form-item label="费用">
                            <a-input v-model="safeItem.fee" placeholder="请输入保障费用" suffix="元" allow-clear></a-input>
                        </a-form-item>
                        <a-form-item label="排序">
                            <a-input v-model="safeItem.sort" placeholder="请输入排序" allow-clear></a-input>
                        </a-form-item>
                        <a-form-item label="是否默认">
                            <a-radio-group v-model="safeItem.isDefault" >
                                <a-radio  v-for="(item,i) in isDefaultList" :key="i" :value="item.id">{{item.name}}</a-radio>
                            </a-radio-group>
                        </a-form-item>
                        <a-form-item label="状态">
                            <a-radio-group v-model="safeItem.status" >
                                <a-radio  v-for="(item,i) in statusList" :key="i" :value="item.id">{{item.name}}</a-radio>
                            </a-radio-group>
                        </a-form-item>
                        <a-form-item v-bind="formItemLayoutWithOutLabel">
                            <a-button  @click="childrenDrawer = false" style="margin-right: 20px">取消</a-button>
                            <a-button type="primary" @click="safeHandOk">确认</a-button>
                        </a-form-item>
                    </a-form>
                </div>
            </a-drawer>
        </a-drawer>
    </div>
</template>

<script>
import { queryTravelVehicleStore , queryTravelVehicleSafeguard , queryTravelVehicleStoreConfig , updateTravelVehicleStoreConfig , queryTravelVehicleSafeguardConfig , updateTravelVehicleSafeguardConfig } from '@/api/travel';
import { columns } from './table';
import { safeColumns } from './safeTable';
import { uploadFile } from '@/api/brand';
import { getBase64 } from '@/utils/util';
import { Ellipsis } from '@/components';
export default {
    components: {
        Ellipsis,
    },
    data () {
        return {
            brandId: this.global.brandId,
            vehicleName: this.$route.query.vehicleName,
            vehicleId: this.$route.query.vehicleId,
            storeId: undefined,
            storeList: [], // 门店列表
            status: undefined,
            statusList: [
                { id: '1', name: '开启'},{ id: '0', name: '关闭'}
            ],
            dataList: [],
            total: 0,
            isload: false,
            page: 1,
            size: 10,
            columns,
            item: {
                'id': '',
                'storeId': undefined, // 租车门店ID
                'rent': '', // 租金，单位：天
                'commission': '', // 手续费
                'deliveryFee': '', // 送车上门服务费
                'pickUpFee': '', // 上门取车服务费
                'freeCancleTime': '', // 免费取消时间，单位：分钟
                'beforePickUpDedit': '', // 取车时间前违约金
                'afterPickUpDedit': '', // 取车时间后违约金
                'realShotImage': '', // 实拍图
                'rentalCarCashPledge': '', // 租车押金
                'breakRulesCashPledge': '', // 违章押金
                'limitMileage': '', // 限制里程，单位：KM/天
                'overLimitFee': '', // 超限费用，单位：元/KM
                'prohibitArea': '', // 禁行区域
                'stock': '', // 库存
                'status': '1',
            },
            colors: ['blue','purple','cyan','green','orange','red','pink','brown','indigo','lime','purple','teal','yellow','amber'],
            confirmLoading: false,
            isAdd: false,
            visible: false,
            imgList: [],
            previewVisible: false,
            previewImage: '',
            previewImgVisible: false,
            showImgs: [],
            safeConfig: false,
            safeList: [],
            safePage: 1,
            safeSize: 10,
            safeTotal: 0,
            safeguardId: undefined,
            safeguardList: [],
            isDefault: undefined,
            isDefaultList: [
                { id: '1', name: '是'},{ id: '0', name: '否'}
            ],
            safeColumns,
            safeStoreId: undefined,
            safeStoreName: '',
            safeItem: {
                'id': '',
                'safeguardId': undefined, // 保障ID
                'fee': '', // 费用
                'isDefault': '1', // 是否默认
                'sort': '', // 排序
                'status': '1', // 状态
            },
            childrenDrawer: false,
            formItemLayoutWithOutLabel: {
                wrapperCol: {
                    xs: { span: 24, offset: 0 },
                    sm: { span: 20, offset: 6 },
                },
            },
        };
    },
    async created(){
        try {
            await this.queryStore();
            await this.querySafeguard();
            this.getData();
        } catch (error) {
            this.$notification['error']({
                message: '提示',
                description: error,
                duration: 8,
            })
        }
    },
    methods: {
        // 获取门店列表
        queryStore(){
            let _this = this
            return new Promise((resolve,reject) => {
                queryTravelVehicleStore({'size': 99,'page': 0})
                .then(res=>{
                    if(res.success){
                        _this.storeList = res.data.content;
                        resolve()
                    }else{
                        reject(res.errMessage)
                    }
                })
            })
        },
        // 获取保障信息
        querySafeguard(){
            let _this = this
            return new Promise((resolve,reject) => {
                queryTravelVehicleSafeguard({'size': 99,'page': 0,'status': 1})
                .then(res=>{
                    if(res.success){
                        _this.safeguardList = res.data.content;
                        resolve()
                    }else{
                        reject(res.errMessage)
                    }
                })
            })
        },
        // 查询车辆租车门店配置信息
        getData(){
            let _this = this;
            _this.isload = true
            const params = {
                'brandId': _this.brandId,
                'storeId': _this.storeId,
                'status': _this.status,
                'vehicleId': _this.vehicleId,
                'page': _this.page - 1,
                'size': _this.size,
            }
            queryTravelVehicleStoreConfig(params)
            .then(res => {
                _this.isload = false
                if(res.success){
                    _this.dataList = res.data.content;
                    _this.total = res.data.totalElements;
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData();
        },
        // 添加产品
        add(){
            this.item.id = ''
            this.item.vehicleId = this.vehicleId;
            this.item.storeId = undefined;
            this.item.rent = '';
            this.item.commission = '';
            this.item.deliveryFee = '';
            this.item.pickUpFee = '';
            this.item.freeCancleTime = '';
            this.item.beforePickUpDedit = '';
            this.item.afterPickUpDedit = '';
            this.item.realShotImage = '';
            this.item.rentalCarCashPledge = '';
            this.item.breakRulesCashPledge = '';
            this.item.limitMileage = '';
            this.item.overLimitFee = '';
            this.item.prohibitArea = '';
            this.item.stock = '';
            this.item.status = '1';
            this.imgList = [];
            this.visible = true
        },
        // 修改产品
        async update(item){
            let _this = this;
            this.item = JSON.parse(JSON.stringify(item));
            this.item.deliveryFee = item.deliveryFee * 100;
            this.item.pickUpFee = item.pickUpFee * 100;
            this.item.beforePickUpDedit = item.beforePickUpDedit * 100;
            this.item.afterPickUpDedit = item.afterPickUpDedit * 100;
            _this.imgList = [];
            if(item.realShotImage && item.realShotImage.substring(0,4) == 'http'){
                var array = item.realShotImage.split(',');
                let _this = this;
                for (let index = 0; index < array.length; index++) {
                    const element = array[index];
                    _this.imgList.push({
                        'uid': index +1,
                        'id': index +1,
                        'url': element,
                        'status':'done',
                        'name':element,
                        'noFile': true,
                    })
                }
            }
            this.visible = true
        },
        // 确认添加、修改车型分类信息
        async handleOk(){ 
            let _this = this
            if(_this.item.storeId == undefined){
                _this.$message.warning('请选择租车门店')
                return;
            }
            if(_this.item.rent == ''){
                _this.$message.warning('请输入每日租金金额')
                return;
            }
            if(_this.item.stock == ''){
                _this.$message.warning('请输入库存数量')
                return;
            }
            var imgList = [];
            if(_this.imgList.length > 0){
                for (let index = 0; index < _this.imgList.length; index++) {
                    const element = _this.imgList[index];
                    console.log(element,'element')
                    if(element.noFile){
                        imgList.push(element.url);
                    }else{
                        try {
                            var imgs = await _this.uploadImg(element.originFileObj,`logo${index}`);
                            console.log(imgs,'imgs');
                            imgList.push(imgs);
                        } catch (error) {
                            _this.$notification['error']({
                                message: '提示',
                                description: error,
                                duration: 8,
                            })
                            return;
                        }
                    }
                }
                _this.item.realShotImage = imgList.join(',');
            }
            const params = {
                'id':_this.item.id,
                'brandId': _this.brandId,
                'vehicleId': _this.item.vehicleId,
                'storeId': _this.item.storeId,
                'rent': _this.item.rent,
                'commission': _this.item.commission,
                'deliveryFee': _this.item.deliveryFee / 100,
                'pickUpFee': _this.item.pickUpFee / 100,
                'freeCancleTime': _this.item.freeCancleTime,
                'beforePickUpDedit': _this.item.beforePickUpDedit /  100,
                'afterPickUpDedit': _this.item.afterPickUpDedit / 100,
                'realShotImage': _this.item.realShotImage,
                'rentalCarCashPledge': _this.item.rentalCarCashPledge,
                'breakRulesCashPledge': _this.item.breakRulesCashPledge,
                'limitMileage': _this.item.limitMileage,
                'overLimitFee': _this.item.overLimitFee,
                'prohibitArea': _this.item.prohibitArea,
                'stock': _this.item.stock,
                'status': _this.item.status,
            }
            updateTravelVehicleStoreConfig(params)
            .then(async res=>{
                if(res.success){
                    _this.visible = false
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: _this.item.id ? '修改成功' : '添加成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 删除产品
        del(item){
            let _this = this
            const params = {
                'id':item.id,
                'vehicleId': item.vehicleId,
                'storeId': item.storeId,
                'rent': item.rent,
                'isDelete':'1',
            }
            updateTravelVehicleStoreConfig(params)
            .then(res=>{
                if(res.success){
                    _this.visible = false
                    _this.getData()
                    _this.$notification['success']({
                        message: '提示',
                        description: '删除成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 预览图片
        showImg(imgs){
            if(imgs){
                this.showImgs = imgs.split(',')
                console.log(this.showImgs,'imgs')
                this.previewImgVisible = true
            }
        },
        getImgUrl(i){
            return this.showImgs[i]
        },
        async handlePreview(file) {
            if (!file.url && !file.preview) {
                file.preview = await getBase64(file.originFileObj);
            }
            this.previewImage = file.url || file.preview;
            this.previewVisible = true;
        },
        imgHandleChange({ fileList }) {
            this.imgList = fileList;
        },
        beforeUpload(file) {
            return false;
        },
        // 上传图片获取图片url
        uploadImg(file,name){
            let _this = this
            return new Promise((resolve,reject) => {
                let formData = new FormData()
                formData.append('brandId',_this.brandId)
                formData.append('urlName',name)
                formData.append('file',file)
                uploadFile(formData)
                .then(res=>{
                    if(res.success){
                        resolve(res.data)
                    }else{
                        reject(res.errMessage);
                    }
                })
            })
        },
        // 商家保障配置
        setSafeConfig(item){
            this.safeStoreId = item.storeId;
            this.safeStoreName = item.storeName;
            this.getSafeData();
            this.safeConfig = true;
        },
        // 查询商家保障配置
        getSafeData(){
            let _this = this;
            _this.isload = true
            const params = {
                'brandId': _this.brandId,
                'storeId': _this.safeStoreId,
                'status': _this.status,
                'vehicleId': _this.vehicleId,
                'isDefault': _this.isDefault,
                'safeguardId': _this.safeguardId,
                'sort': 'sort',
                'page': _this.page - 1,
                'size': _this.size,
            }
            queryTravelVehicleSafeguardConfig(params)
            .then(res => {
                _this.isload = false
                if(res.success){
                    _this.safeList = res.data.content;
                    _this.safeTotal = res.data.totalElements;
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        safeHandleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.safePage = pagination.current;
            this.safeSize = pagination.pageSize;
            this.getSafeData();
        },
        // 添加
        safeAdd(){
            this.safeItem.id = '';
            this.safeItem.vehicleId = this.vehicleId;
            this.safeItem.storeId = this.safeStoreId;
            this.safeItem.safeguardId = undefined;
            this.safeItem.fee = '';
            this.safeItem.isDefault = '1';
            this.safeItem.sort = '';
            this.safeItem.status = '1';
            this.childrenDrawer = true;
        },
        // 修改
        safeUpdate(item){
            this.safeItem = JSON.parse(JSON.stringify(item));
            this.childrenDrawer = true;
        },
        // 确认添加、修改
        safeHandOk(){
            let _this = this;
            if(_this.safeItem.safeguardId == undefined){
                _this.$message.warning('请选择保障类型')
                return;
            }
            if(_this.safeItem.fee == ''){
                _this.$message.warning('请输入保障费用')
                return;
            }
            const params = {
                'id': _this.safeItem.id,
                'brandId': _this.brandId,
                'vehicleId': _this.safeItem.vehicleId,
                'storeId': _this.safeItem.storeId,
                'safeguardId': _this.safeItem.safeguardId,
                'fee': _this.safeItem.fee,
                'isDefault': _this.safeItem.isDefault,
                'sort': _this.safeItem.sort,
                'status': _this.safeItem.status,
            }
            updateTravelVehicleSafeguardConfig(params)
            .then(res => {
                if(res.success){
                    _this.childrenDrawer = false
                    _this.getSafeData()
                    _this.$notification['success']({
                        message: '提示',
                        description: _this.safeItem.id ? '修改成功' : '添加成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
        // 删除产品
        safeDel(item){
            let _this = this
            const params = {
                'id':item.id,
                'vehicleId': item.vehicleId,
                'storeId': item.storeId,
                'fee': item.fee,
                'isDelete':'1',
            }
            updateTravelVehicleSafeguardConfig(params)
            .then(res=>{
                if(res.success){
                    _this.childrenDrawer = false
                    _this.getSafeData()
                    _this.$notification['success']({
                        message: '提示',
                        description: '删除成功',
                        duration: 8,
                    })
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8,
                    })
                }
            })
        },
    }
}

</script>
<style scoped>

</style>